package edu.cuit.zhuyimeng.flight.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import edu.cuit.zhuyimeng.flight.controller.dto.QueryFlightDTO;
import edu.cuit.zhuyimeng.flight.controller.vo.FlightInfoVO;
import edu.cuit.zhuyimeng.flight.service.IFlightQueryService;
import edu.cuit.zhuyimeng.framework.common.result.CommonResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户航班控制器
 */
@Tag(name = "用户航班控制器")
@RestController
@RequestMapping("/flight")
@Validated
@RequiredArgsConstructor
public class UserController {

    private final IFlightQueryService flightQueryService;

    /**
     * 查询所有航班
     */
    @GetMapping("/")
    @Operation(summary = "查询所有航班")
    public CommonResult<List<FlightInfoVO>> queryAllFlight(@RequestParam("page") @NotNull Integer page) {
        return CommonResult.success(flightQueryService.queryAllFlight(page));
    }

    /**
     * 查询航班数目
     */
    @GetMapping("/amount")
    @Operation(summary = "查询航班数目")
    public CommonResult<Integer> queryAllFlightAmount() {
        return CommonResult.success(flightQueryService.queryAllFlightAmount());
    }

    /**
     * 查询空闲航班
     */
    @PostMapping("/idle")
    @Operation(summary = "查询指定地点时间的空闲航班")
    public CommonResult<List<FlightInfoVO>> queryIdleFlight(@RequestBody @Valid QueryFlightDTO queryFlightDTO) {
        return CommonResult.success(flightQueryService.queryIdleFlight(queryFlightDTO));
    }

    /**
     * 查询相似航班
     */
    @GetMapping("/similar")
    @Operation(summary = "查询相似航班")
    public CommonResult<List<FlightInfoVO>> querySimilarFlight(@RequestParam("id") @NotNull Long id) {
        return CommonResult.success(flightQueryService.querySimilarFlight(id));
    }

    /**
     * 查询某个航班
     */
    @GetMapping("/{id}")
    @Operation(summary = "查询某个航班")
    public CommonResult<FlightInfoVO> queryOneFlight(@PathVariable("id") @NotNull Long id) {
        return CommonResult.success(flightQueryService.queryOneFlight(id));
    }

}
